package com.d3works.apps.purchase.service;

import com.d3works.apps.account.db.TaxLine;
import com.d3works.apps.base.db.PriceList;
import com.d3works.apps.base.db.PriceListLine;
import com.d3works.apps.base.db.Product;
import com.d3works.apps.base.db.Unit;
import com.d3works.apps.purchase.db.PurchaseOrder;
import com.d3works.apps.purchase.db.PurchaseOrderLine;
import com.d3works.apps.purchase.db.SupplierCatalog;
import com.d3works.exception.D3worksException;
import com.d3works.rpc.ActionResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface PurchaseOrderLineService {

  public BigDecimal getExTaxUnitPrice(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine, TaxLine taxLine)
      throws D3worksException;

  public BigDecimal getInTaxUnitPrice(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine, TaxLine taxLine)
      throws D3worksException;

  public BigDecimal getPurchaseMaxPrice(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws D3worksException;

  public TaxLine getTaxLine(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine)
      throws D3worksException;

  /**
   * Get optional tax line.
   *
   * @param purchaseOrder
   * @param purchaseOrderLine
   * @return
   */
  Optional<TaxLine> getOptionalTaxLine(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine);

  public BigDecimal computePurchaseOrderLine(PurchaseOrderLine purchaseOrderLine);

  public BigDecimal getCompanyExTaxTotal(BigDecimal exTaxTotal, PurchaseOrder purchaseOrder)
      throws D3worksException;

  public PriceListLine getPriceListLine(
      PurchaseOrderLine purchaseOrderLine, PriceList priceList, BigDecimal price);

  public Map<String, BigDecimal> compute(
      PurchaseOrderLine purchaseOrderLine, PurchaseOrder purchaseOrder) throws D3worksException;

  public BigDecimal computeDiscount(PurchaseOrderLine purchaseOrderLine, Boolean inAti);

  public PurchaseOrderLine createPurchaseOrderLine(
      PurchaseOrder purchaseOrder,
      Product product,
      String productName,
      String description,
      BigDecimal qty,
      Unit unit)
      throws D3worksException;

  public SupplierCatalog getSupplierCatalog(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws D3worksException;

  public Map<String, Object> updateInfoFromCatalog(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws D3worksException;

  public Map<String, Object> getDiscountsFromPriceLists(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine, BigDecimal price);

  public int getDiscountTypeSelect(
      PurchaseOrderLine purchaseOrderLine, PurchaseOrder purchaseOrder, BigDecimal price);

  public Unit getPurchaseUnit(PurchaseOrderLine purchaseOrderLine);

  public void checkMultipleQty(PurchaseOrderLine purchaseOrderLine, ActionResponse response);

  public String[] getProductSupplierInfos(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine) throws D3worksException;

  PurchaseOrderLine fill(PurchaseOrderLine line, PurchaseOrder purchaseOrder)
      throws D3worksException;

  PurchaseOrderLine reset(PurchaseOrderLine line);

  public void checkDifferentSupplier(
      PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine, ActionResponse response);

  public List<PurchaseOrderLine> updateLinesAfterFiscalPositionChange(PurchaseOrder purchaseOrder)
      throws D3worksException;
}
